<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<title>统计管理</title>
<script type="text/javascript" src="__PUBLIC__/Admin/js/jquery.js"></script> 
<script type="text/javascript" src="__PUBLIC__/Admin/js/echarts.min.js"></script> 
<link rel="stylesheet" type="text/css" href="__PUBLIC__/Admin/css/tongji.css">
<script type="text/javascript">
  var tongji_url="{:U('admin/tongji/ajax')}";

</script>
</head>
<body>
      <!-- 为ECharts准备一个具备大小（宽高）的Dom -->
    <div id="main" style="width: 600px;height:400px;"></div>
    <script type="text/javascript">
      var num =[]; //与var num = array();
      var date = [];
      //解释：var num = array 是PHP写法
      $.ajax({
        type: "post",
        async: false, //同步执行
        url: tongji_url,
        dataType: "json",
        success:function (result) {
            if (result) {
              // for(var index in result){
              //    num[index] = result[index].num;
              //    date[index] = result[index].date;
              // }
              // alert(result.length);
              for (var i=0; i <= result.length; i++) {
                  num[i] = result[i].num;
                  date[i] = result[i].date;
                  // alert(num);
                  // alert(date);
              };

            }
        },
        error: function (errorMsg) {
            alert("不好意思，大爷，图表请求数据失败啦!");
        }
      });
        // 基于准备好的dom，初始化echarts实例
        var myChart = echarts.init(document.getElementById('main'));
        option = {
            tooltip : {
                trigger: 'axis',
                axisPointer : {            // 坐标轴指示器，坐标轴触发有效
                    type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
                }
            },
            legend: {
                data:['一周内注册的用户']
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            xAxis : [
                {
                    type : 'category',
                    data : date
                }
            ],
            yAxis : [
                {
                    type : 'value'
                }
            ],
            series : [
                {
                    name:'一周注册的用户',
                    type:'bar',
                    data:num
                },
            
            ]
        };

        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);
    </script>
</body>
</html>